package com.jack.payment.controller.admin.noauth;


import com.jack.payment.cache.AppointDetailServiceImpl;
import com.jack.payment.constant.ResultHintConstant;
import com.jack.payment.constant.enums.PaymentStatusEnum;
import com.jack.payment.entity.common.BusinessException;
import com.jack.payment.entity.common.CommonAskParam;
import com.jack.payment.entity.common.CommonResult;
import com.jack.payment.entity.generate.payment.PaymentAttachModel;
import com.jack.payment.entity.request.OneFieldModel;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@Tag(name = "公共")
@RequestMapping("/api/v1/common")
public class CommonController {
    private Logger log = LoggerFactory.getLogger(CommonController.class);


    @Autowired
    private AppointDetailServiceImpl appointDetailService;


    @Operation(summary = "验证此订单是否支付")
    @RequestMapping(value = "verifyPaySuccess", method = { RequestMethod.POST })
    @ResponseBody
    public CommonResult verifyPaySuccess(@RequestBody CommonAskParam<OneFieldModel> data) throws BusinessException {
        String orderNo = data.getData().getField();
        PaymentAttachModel attachModel = appointDetailService.getAppointPaymentAttachDetail(orderNo);
        if (attachModel.getStatus() == PaymentStatusEnum.WAIT_PAY.getStat()) {
            throw new BusinessException(ResultHintConstant.WAIT_PAY);
        }
        if (attachModel.getStatus() != PaymentStatusEnum.PAY.getStat()) {
            throw new BusinessException(ResultHintConstant.PAY_UPDATE);
        }
        return CommonResult.ok(200, ResultHintConstant.PAY_SUCCESS);
    }
}
